package mgslangpack;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;

public class UpdateMem
{
    public UpdateMem() throws Exception
    {
        final TextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10;
        Label l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11;
        Button b1,b2,b3;
        final JFrame f;

        f= new JFrame("Update Member Info");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(800,700);
        f.setLayout(null);
        f.setVisible(false);

        Container ctn=f.getContentPane();
        ctn.setBackground(Color.LIGHT_GRAY);
        JLabel Pic;
        Pic=new JLabel(new ImageIcon("wedding-ring.jpg"));
        Pic.setBounds(200,340,450,398);
        ctn.add(Pic);

        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        final Connection con =
        DriverManager.getConnection("jdbc:odbc:TheOZ_DB","","");

        Font f1 = new Font("Times New roman",Font.BOLD,24);
        l1 = new Label("Update Club member's details:");
        l1.setBounds(50,10,500,40);
        l1.setFont(f1);
        f.add(l1);

        l2=new Label("ID Number:");
        l2.setBounds(50,50,100,30);
        f.add(l2);
        tf1 = new TextField(); tf1.setBounds( 200,50,250,25); f.add(tf1);

        l3=new Label("Name:");
        l3.setBounds(50,90,100,30);
        f.add(l3);
        tf2 = new TextField(); tf2.setBounds( 200,90,150,25); f.add(tf2);

        l4= new Label("Surname:");
        l4.setBounds(400,90,100,30);
        f.add(l4);
        tf3=new TextField(); tf3.setBounds( 500,90,150,25); f.add(tf3);

        l5= new Label("Phone No. (H/W):");
        l5.setBounds(50,130,100,30);
        f.add(l5);
        tf4=new TextField(); tf4.setBounds( 200,130,150,25); f.add(tf4);

        l6= new Label("Cell Number:");
        l6.setBounds(400,130,100,30);
        f.add(l6);
        tf5=new TextField(); tf5.setBounds( 500,130,150,25); f.add(tf5);

        l7= new Label("E-mail Address:");
        l7.setBounds(50,170,150,30);
        f.add(l7);
        tf6=new TextField(); tf6.setBounds( 200,170,230,25); f.add(tf6);

        l8=new Label("Address:");
        l8.setBounds(50,210,100,30);
        f.add(l8);
        tf7=new TextField(); tf7.setBounds( 200,210,200,25); f.add(tf7);

        l9= new Label("Suburb:");
        l9.setBounds(50,250,100,30);
        f.add(l9);
        tf8=new TextField(); tf8.setBounds( 200,250,185,25); f.add(tf8);

        l10= new Label("Town:");
        l10.setBounds(50,290,100,30);
        f.add(l10);
        tf9=new TextField(); tf9.setBounds( 200,290,150,25); f.add(tf9);

        l11= new Label("Code:");
        l11.setBounds(400,290,100,30);
        f.add(l11);
        tf10 = new TextField(); tf10.setBounds( 550,290,100,25); f.add(tf10);

        b1 = new Button("Update");
        b1.setBounds(50,330,80,30);
        b1.addActionListener( new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                try
                {
                    String s1,s2,s3,s4,s5,s6,s7,s8,s9,s10;
                    s1=tf1.getText();
                    s2=tf2.getText();
                    s3=tf3.getText();
                    s4=tf4.getText();
                    s5=tf5.getText();
                    s6=tf6.getText();
                    s7=tf7.getText();
                    s8=tf8.getText();
                    s9=tf9.getText();
                    s10=tf10.getText();
                    PreparedStatement ps = con.prepareStatement("UPDATE Member SET MemFirstName="+s2+", MemLastName="+s3+", MemPhoneNo="+s4+", MemCellNo="+s5+", MemEmail="+s6+", MemPOBox="+s7+", MemSuburb="+s8+", MemTown="+s9+", MemCode="+s10+" WHERE MemID="+s1);
                    int i = ps.executeUpdate();
                    JOptionPane.showMessageDialog(null,"Club members deails\nUpdated");
                    tf1.setText("");
                    tf2.setText("");
                    tf3.setText("");
                    tf4.setText("");
                    tf5.setText("");
                    tf6.setText("");
                    tf7.setText("");
                    tf8.setText("");
                    tf9.setText("");
                    tf10.setText("");
                }
                catch(Exception e1){JOptionPane.showMessageDialog(null,"Error!\nCould not update record.");}
            }
        }
        );

        f.add(b1);

        b2 = new Button("Back");
        b2.setBounds(50,370,80,30);
        b2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e2)
            {
                try
                {
                    f.hide();
                }
                catch(Exception e3){}
            }
        }
        );

        f.add(b2);
        b3 = new Button("Exit");
        b3.setBounds(650,50,80,30);
        b3.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e2)
            {
                try
                {
                    System.exit(0);
                }
                catch(Exception e3){}
            }
        }
        );

        f.add(b3);
        f.show();
    }
}
/******************************************************************************/